package com.example.taximeter.mapper;

import com.example.taximeter.bean.Privilege;
import com.example.taximeter.bean.Role;
import com.example.taximeter.bean.RolePrivilege;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 权限
 */
@Mapper
public interface PrivilegeMapper {


    //查询绑定的权限信息(roleid)
    @Select("select privilege_id from tab_role_privilege where role_id = #{roleid,jdbcType=INTEGER}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "privilegeid", column = "privilege_id")
    })
    List<RolePrivilege> findRolePrivilegeByRoleid(@Param("roleid")Integer id);

    //查询当前用户权限信息
    @Select("select privilege_id,privilege_name,privilege_parent,leaf_nod from tab_privileges where privilege_id = #{privilegeid,jdbcType=INTEGER}")
    @Results({
            @Result(property = "privilegeid", column = "privilege_id"),
            @Result(property = "privilegename", column = "privilege_name"),
            @Result(property = "privilegeparent", column = "privilege_parent"),
            @Result(property = "leafnod", column = "leaf_nod")
    })
    Privilege findPrivilegeByRoleid(@Param("privilegeid")Integer privilegeid);

    //查询当前用户权限信息
    @Select("select privilege_id,privilege_name,privilege_parent,leaf_nod from tab_privileges")
    @Results({
            @Result(property = "privilegeid", column = "privilege_id"),
            @Result(property = "privilegename", column = "privilege_name"),
            @Result(property = "privilegeparent", column = "privilege_parent"),
            @Result(property = "leafnod", column = "leaf_nod")
    })
    List<Privilege> findPrivilegelist();

    //查询绑定的权限信息(roleid)
    @Select("select * from role_privilege where role_id = #{roleid,jdbcType=INTEGER}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "privilegeid", column = "privilege_id"),
            @Result(property = "privilegename", column = "privilege_name"),
            @Result(property = "privilegeparent", column = "privilege_parent"),
            @Result(property = "leafnod", column = "leaf_nod")
    })
    List<RolePrivilege> findRolePrivilegeAllByRoleid(@Param("roleid")Integer id);


    //删除绑定信息
    @Delete("delete from tab_role_privilege where role_id = #{roleid,jdbcType=INTEGER}")
    boolean deleteRolePrivilege(Integer roleid);
}
